package com.yixun.qfbao.hander;

import com.yixun.qfbao.api.service.ChannelRoleService;
import com.yixun.qfbao.apidto.GetChannelRoleListReqDto;
import com.yixun.qfbao.apidto.GetChannelRoleListResDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.model.PartnerInfo;
import com.yixun.qfbao.utils.LoginUtils;
import com.yixun.qfbao.vo.GetChannelRoleListReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 获取角色列表（用做下拉框）
 * @author guifang.weng
 * @create 2017-11-22 9:56
 **/
@Service("getChannelRoleListHander")
public class GetChannelRoleListHander extends CommonAbstractHander {
    private static Logger logger= LoggerFactory.getLogger(GetChannelRoleListHander.class);

    @Autowired
    private ChannelRoleService channelRoleService;

    @Autowired
    private LoginUtils loginUtils;

    @Override
    public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
        BaseResponseDTO<GetChannelRoleListResDto> res = new BaseResponseDTO<>();
        GetChannelRoleListReqVo getChannelRoleListReqVo = (GetChannelRoleListReqVo)reqDto;
        GetChannelRoleListReqDto getChannelRoleListReqDto = getChannelRoleListReqVo.getParams();
        PartnerInfo pi = loginUtils.getUser(getChannelRoleListReqDto.getUserId());
        if(pi == null){
            res.setResult(ResultEnum.FAIL.getNo());
            res.setErrorMsg("未找到用户信息");
            return res;
        }
        getChannelRoleListReqDto.setMerchantId(pi.getHigherid());
        try {
            GetChannelRoleListResDto resDto = channelRoleService.getChannelRoleList(getChannelRoleListReqDto);
            res.setResult(resDto.getResult());
            res.setResData(resDto);
        } catch (Exception e) {
            logger.error("GetPremisesCommissionHander error: {}", e);
            res.setResult(ResultEnum.FAIL.getNo());
            res.setErrorMsg("获取角色列表失败");
        }
        return res;
    }
}
